#include "defines.h"

int main(int argc, char * argv[]) {

	struct timeval start, end;
	
	int t, x;
	int N  = atoi(argv[1]);
	int T  = atoi(argv[2]);
	int Bx = atoi(argv[3]);
	int tb = atoi(argv[4]);

	if(Bx<(2*XSLOPE+1) || Bx>N || tb>(((Bx-1)/2)/XSLOPE)){ 
		return 0;
	}

	double (*A)[N+2*XSTART] = (double (*)[N+2*XSTART])malloc(sizeof(double)*(N+2*XSTART)*2);
#ifdef CHECK
	double (*B)[N+2*XSTART] = (double (*)[N+2*XSTART])malloc(sizeof(double)*(N+2*XSTART)*2);
#endif


	srand(100);
	for (x = 0; x < N+2*XSTART; x++) {
		A[0][x] = 1.0 * (rand() % 1024);
		A[1][x] = A[0][x];
#ifdef CHECK
		B[0][x] = A[0][x];
		B[1][x] = A[0][x];
#endif
		}


	gettimeofday(&start, 0);
	test((double *) A, N, T, Bx, tb);
	gettimeofday(&end, 0);
	printf("GStencil/s = %f\n",((double)N * T) / (double)(end.tv_sec - start.tv_sec + (end.tv_usec - start.tv_usec) * 1.0e-6) / 1000000000L);

#ifdef CHECK
	for (t = 0; t < T; t++) {
		for (x = XSTART; x < N + XSTART; x++) {
			kernel(B);
		}
	}
	for (x = XSTART; x < N + XSTART; x++) {
		if(A[T%2][x] != B[T%2][x])
			printf("Correct[%d] = %f, Wrong = %f: FAILED!\n", x, B[T%2][x], A[T%2][x]);
	}
#endif
}
